#include "../begonia.h"
#include "needlebullet.h"
#include "../base/scene.h"

needlebullet::needlebullet(double tx,double ty,double tr,double tvx,double tvy,double twidth,bullet *h):bullet(tx,ty,tr,tvx,tvy,h)
{
        width=twidth;
        direction0();
}
void needlebullet::direction(double dir)
{
        lx=(r+width)*cos(dir);
        ly=(r+width)*sin(dir);
        wx=width*sin(dir);
        wy=-width*cos(dir);
} 
void needlebullet::clone(bullet *h)
{
    needlebullet *a=new needlebullet(x,y,r,vx,vy,width,h);
    a->c_r=c_r;
    a->c_g=c_g;
    a->c_b=c_b;
}
void needlebullet::show()
{
        glPushMatrix();
            glTranslated(x,y,0.0);
            glColor3d(c_r,c_g,c_b);
            glBegin(GL_POLYGON);
                glVertex2d(lx,ly);
                glVertex2d(wx,wy);
                glVertex2d(-lx,-ly);
                glVertex2d(-wx,-wy);
            glEnd();
            glColor3d(0.0,0.0,0.0);
            glBegin(GL_LINE_LOOP);
                glVertex2d(lx,ly);
                glVertex2d(wx,wy);
                glVertex2d(-lx,-ly);
                glVertex2d(-wx,-wy);
            glEnd();
        glPopMatrix();
}

bool needlebullet::judge()
{
    //tomo
    double dx,dy,d1,d2,v;
    v=sqrt(sqr(vx)+sqr(vy));
    dx=f.px-x;
    dy=f.py-y;
    d2=(dx*vy-dy*vx)/v;
    d1=(dx*vx+dy*vy)/v;
    return abs(d2)<corermax&&abs(d1)<r;
}

